﻿<!DOCTYPE HTML>
<html lang="zh">
<head>
<title>SoundGetName - 语法 &amp; 使用 | AutoHotkey v2</title>
<meta name="description" content="The SoundGetName function retrieves the name of a sound device or component." />
<meta name="ahk:equiv-v1" content="commands/SoundGet.htm" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<link href="../static/theme.css" rel="stylesheet" type="text/css" />
<script src="../static/content.js" type="text/javascript"></script>
<script type="text/javascript">$(function(){0<=window.navigator.userAgent.toLowerCase().indexOf("ucbrowser")&&CaoNiMaDeUc()})</script>
</head>
<body>

<h1>SoundGetName</h1>

<p>检索声音设备或组件的名称.</p>

<pre class="Syntax">Name := <span class="func">SoundGetName</span>(<span class="optional">Component, Device</span>)</pre>
<h2 id="Parameters">参数</h2>
<dl>

  <dt>Component</dt>
  <dd>
    <p>类型: <a href="../Concepts.htm#strings">字符串</a>或<a href="../Concepts.htm#numbers">整数</a></p>
    <p>组件的显示名称和/或索引. 例如, <code>1</code>, <code>"Line in"</code> 或 <code>"Line in:2"</code>.</p>
    <p>如果省略或为空, 将检索设备本身的名称.</p>
    <p>有关详情, 请参阅 <a href="Sound.htm#component">Component (Sound 函数)</a>.</p>
  </dd>

  <dt>Device</dt>
  <dd>
    <p>类型: <a href="../Concepts.htm#strings">字符串</a>或<a href="../Concepts.htm#numbers">整数</a></p>
    <p>设备的显示名称和/或索引. 例如, <code>1</code>, <code>"Speakers"</code>, <code>"Speakers:2"</code> 或 <code>"Speakers (Example HD Audio)"</code>.</p>
    <p>如果省略该参数, 则它默认为系统的默认回放设备(不一定是设备 1).</p>
    <p>有关详情, 请参阅 <a href="Sound.htm#device">Device (Sound 函数)</a>.</p>
  </dd>

</dl>

<h2 id="Return_Value">返回值</h2>
<p>类型: <a href="../Concepts.htm#strings">字符串</a></p>
<p>设备或组件的名称, 可以为空.</p>

<h2 id="Error_Handling">错误处理</h2>
<p>失败时可能会抛出以下异常之一:</p>
<table class="info">
  <tr><th abbr="Class">Error 类</th><th>消息</th></tr>
  <tr><td rowspan="2"><a href="../objects/Error.htm#TargetError">TargetError</a></td><td>Device not found(无法找到设备)</td></tr>
  <tr><td>Component not found(无法找到组件)</td></tr>
  <tr><td><a href="../objects/Error.htm#OSError">OSError</a></td><td><em>System-generated.(由系统生成)</em></td></tr>
</table>

<h2 id="Related">相关</h2>
<p><a href="Sound.htm">Sound 函数</a></p>

<h2 id="Examples">示例</h2>
<div class="ex" id="ExNoParams">
<p><a class="ex_number" href="#ExNoParams"></a> 检索并报告默认播放设备的名称.</p>
<pre>default_device := SoundGetName()
MsgBox 'The default playback device is "' default_device '".'</pre>
</div>

<div class="ex" id="ExDevice">
<p><a class="ex_number" href="#ExDevice"></a> 检索并报告第一个设备的名称.</p>
<pre>device1 := SoundGetName( , 1)
MsgBox 'Device 1 is "' device1 '".'</pre>
</div>

<div class="ex" id="ExComponent">
<p><a class="ex_number" href="#ExComponent"></a> 索并报告第一个组件的名称.</p>
<pre>component1 := SoundGetName(1)
MsgBox 'Component 1 is "' component1 '".'</pre>
</div>

<p>有关更复杂的示例, 请参阅<a href="Sound.htm#ExSoundcard">声卡分析脚本</a>.</p>


</body>
</html>